package cn.wolfcode.p2p.controller;

import cn.wolfcode.p2p.base.anno.NeedLogin;
import cn.wolfcode.p2p.base.domain.RealAuth;
import cn.wolfcode.p2p.base.exception.CustomerException;
import cn.wolfcode.p2p.base.query.QueryObject;
import cn.wolfcode.p2p.base.query.RealAuthQuery;
import cn.wolfcode.p2p.base.service.IRealAuthService;
import cn.wolfcode.p2p.util.JsonResult;
import cn.wolfcode.p2p.util.UploadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Controller

public class RealAuthController {
    @Autowired
    private IRealAuthService realAuthService;

    @RequestMapping("realAuth")
    @NeedLogin
    public String realAuth(Model model, @ModelAttribute("qo")RealAuthQuery qo){
        model.addAttribute("pageInfo",  realAuthService.query(qo));
        return "realAuth/list";
    }

    @RequestMapping("realAuth_audit")
    @ResponseBody
    @NeedLogin
    public JsonResult realAuthAudit(Long id, int state, String remark){
        JsonResult jsonResult = new JsonResult();
        try {
            realAuthService.audit(id, state, remark);
        } catch (CustomerException e) {
            jsonResult.setMessage(e.getMessage());
            throw new CustomerException(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("系统繁忙中,请稍后再试");
        }
        return jsonResult;
    }

}
